<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<%@ taglib prefix="his_fns" uri="/WEB-INF/tlds/his_fns.tld" %>
<div class="content-wrap">
    <div class="wrapper" style="bottom: 50px;">
        <ul class="nav nav-tabs">
            <li class="active">
                <a href="#"   onclick="loadDiv('mainCenterDiv','${ctx}/drug/buyPlanAudit/index')">采购计划审核</a>
            </li>
        </ul>
        <section class="panel panel-default">
            <div class="panel-body">
                <div class="table-responsive no-border">
                    <div class="datatable-top">
                        <div class="pull-left">
                            <form:form id="searchForm" modelAttribute="drugBuyPlan"  onsubmit="return loadDivForm('mainCenterDiv','searchForm','${ctx}/drug/buyPlanAudit/index');" method="post" class="form-inline">
                                <div class="form-group">
                                    <label class=" control-label">采购单号：</label>
                                    <form:select path="purchaseNumber" id="purchaseNumber" htmlEscape="false" class="form-control" data-parsley-required="true">
                                        <form:option value=""></form:option>
                                        <form:options items="${his_fns:getBuyPlanNum('1')}" itemLabel="purchaseNumber" itemValue="purchaseNumber" htmlEscape="false" />
                                    </form:select>
                                </div>
                                <div class="form-group">
                                    <input id="btnSubmit" class="btn btn-primary" type="submit" value="查询" />
                                    <input id="saveBtn" class="btn btn-primary" type="button" onclick="saveDrugPlanAudit()" value="保存" />
                                </div>
                            </form:form>
                        </div>
                    </div>
                    <form id="saveDrugPlanAudit" action="${ctx}/drug/buyPlanAudit/saveDrugPlanAudit" method="post" class="form-inline">
                        <table id="contentTable" class="table table-bordered table-striped mg-t datatable">
                            <thead>
                                <tr>
                                    <th hidden>jsonText</th>
                                    <th hidden>id</th>
                                    <th hidden>stateFlag</th>
                                    <th hidden>infoId</th>
                                    <th hidden>采购序号</th>
                                    <th hidden>采购单号</th>
                                    <th hidden>药品编码</th>
                                    <th>药品名称</th>
                                    <th hidden>包装数量</th>
                                    <th>包装规格</th>
                                    <th hidden>包装单位代码</th>
                                    <th>包装单位</th>
                                    <th hidden>剂型</th>
                                    <th hidden>厂家ID</th>
                                    <th>厂家</th>
                                    <th style="width: 25px;">进价</th>
                                    <th>计划数量</th>
                                    <th>计划金额</th>
                                    <th>申请者</th>
                                    <th hidden>采购数量</th>
                                    <th hidden>采购金额</th>
                                    <th>审核数量</th>
                                    <th hidden>采购供应商ID</th>
                                    <th hidden>采购供应商</th>
                                    <%--<th>库存参考数</th>--%>
                                    <%--<th>月消耗量</th>--%>
                                    <th>操作</th>
                                </tr>
                            </thead>
                            <tbody>
                            <c:forEach items="${page.list}" var="drugBuyPlan" varStatus="idx">
                            <tr xia="${idx.index}">
                                <td hidden>${drugBuyPlan.id}<input type="hidden" id="id${idx.index}" name="drugBuyPlanList[${idx.index}].id" value="${drugBuyPlan.id}" /></td>
                                <td hidden>${drugBuyPlan.stateFlag}<input type="hidden" name="drugBuyPlanList[${idx.index}].stateFlag" value="${drugBuyPlan.stateFlag}" /></td>
                                <td hidden> ${drugBuyPlan.infoId}<input type="hidden" id="infoId${idx.index}" name="drugBuyPlanList[${idx.index}].infoId" value="${drugBuyPlan.infoId}" /></td>
                                <td hidden> ${drugBuyPlan.purchaseOrder}<input type="hidden" id="purchaseOrder${idx.index}" name="drugBuyPlanList[${idx.index}].purchaseOrder"
                                                                               value="${drugBuyPlan.purchaseOrder}" /></td>
                                <td hidden> ${drugBuyPlan.purchaseNumber}<input type="hidden" id="purchaseNumber${idx.index}" name="drugBuyPlanList[${idx.index}].purchaseNumber"
                                                                                value="${drugBuyPlan.purchaseNumber}" /></td>
                                <td hidden> ${drugBuyPlan.drugCode}<input type="hidden" name="drugBuyPlanList[${idx.index}].drugCode" value="${drugBuyPlan.drugCode}" /></td>
                                <td> ${drugBuyPlan.drugName}<input type="hidden" name="drugBuyPlanList[${idx.index}].drugName" value="${drugBuyPlan.drugName}" /></td>
                                <td hidden> ${drugBuyPlan.drugStock.drugInfo.packageNum}<input type="hidden" name="drugBuyPlanList[${idx.index}].drugStock.drugInfo.packageNum"
                                                                                        value="${drugBuyPlan.drugStock.drugInfo.packageNum}" /></td>
                                <td> ${drugBuyPlan.packageSpec}<input type="hidden" name="drugBuyPlanList[${idx.index}].packageSpec" value="${drugBuyPlan.packageSpec}" /></td>
                                <td hidden> ${drugBuyPlan.packageUnit}<input type="hidden" name="drugBuyPlanList[${idx.index}].packageUnit" value="${drugBuyPlan.packageUnit}" /></td>
                                <td> ${fns:getDictLabel(drugBuyPlan.packageUnit,'SPEC_UNIT' ,'' )}</td>
                                <td hidden>${drugBuyPlan.drugForm}<input type="hidden" name="drugBuyPlanList[${idx.index}].drugForm" value="${drugBuyPlan.drugForm}" /></td>
                                <td hidden> ${drugBuyPlan.vedorName}<input type="hidden" name="drugBuyPlanList[${idx.index}].vedorName" value="${drugBuyPlan.vedorName}" /></td>
                                <td> ${his_fns:getSupplierById(drugBuyPlan.vedorName)}</td>
                                    <%--进价--%>
                                <td><input name="drugBuyPlanList[${idx.index}].costPrice" id="costPrice${idx.index}" value="${drugBuyPlan.costPrice}" class="form-control"></td>
                                <td> ${drugBuyPlan.plannedSelling}<input type="hidden" name="drugBuyPlanList[${idx.index}].plannedSelling" value="${drugBuyPlan.plannedSelling}" /></td>
                                <td> ${drugBuyPlan.plannedAmount}<input type="hidden" name="drugBuyPlanList[${idx.index}].plannedAmount" value="${drugBuyPlan.plannedAmount}" /></td>
                                <td>${his_fns:getNameByUserId(drugBuyPlan.warehouseKeeper)}
                                    <input type="hidden" name="drugBuyPlanList[${idx.index}].warehouseKeeper" value="${drugBuyPlan.warehouseKeeper}" /></td>
                                    <%--审核数量--%>
                                <td><input name="drugBuyPlanList[${idx.index}].auditSelling" id="amount${idx.index}" value="${drugBuyPlan.plannedSelling}"
                                           class="form-control" width="20px"></td>
                                <%--<td> ${drugBuyPlan.drugStock.quantity}</td>--%>
                                <%--<td>${drugBuyPlan.monthUsed}</td>--%>
                                <td>
                                    <a href="#" class="applyBt btn btn-danger btn-xs" onclick="removeList(${idx.index},this)">删除</a>
                                </td>
                            </tr>
                            </c:forEach>
                        </table>
                    </form>
                </div>
            </div>
        </section>
    </div>
</div>
<script>
    //保存
    function saveDrugPlanAudit() {
        $("#saveDrugPlanAudit").ajaxSubmit({
            success: function (data) {
                if (data.code == 'success') {
                    toastr.success(data.data);
                    loadDiv('mainCenterDiv', '${ctx}/drug/buyPlanAudit/index');
                } else {
                    toastr.error(data.data);
                }
            },
            error: function (data) {
                toastr.error(data.data);
            }
        });
    }
    //删除
    function removeList(tbIdx, btn) {
        var purchaseNumber = $('#purchaseNumber' + tbIdx).val();
        if (tbIdx == Number($("#contentTableU tbody tr:last").attr('xia'))) {   //删除的是最后一行

        } else {
            $("#contentTableU tbody tr").each(function (index, item) {    //删除的不是最后一行

            });
        }
        var id = $('#id' + tbIdx).val();
        if (null == id || $.trim(id) == '' || typeof(id) == 'undefined') {
            toastr.success('删除成功!');
            $(btn).parent().parent().remove();
            return;
        }
        $.ajax({
            type: "POST",
            url: '${ctx}/drug/buyPlanAudit/delete?id=' + id,
            success: function (data) {
                if (data.code == "success") {
                    toastr.success(data.data);
                    $(btn).parent().parent().remove();
                } else {
                    toastr.error(data.data);
                }
            },
            error: function (data) {
                toastr.error('网络连接错误,请检查网络');
            }
        });
    }
</script>